import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int limit = scanner.nextInt();
        int[] array = new int[10];
        for(int i = 0;i<n;i++){
            array[i] = scanner.nextInt();
        }

        Solution solution = new Solution();
        solution.distributeCandies(n,limit);
    }
}

class Solution {
    public long distributeCandies(int n, int limit) {
        long res=0;
        for (int i = 0; i <=Math.min(limit,n) ; i++) {
            if(n-i>2*limit){
                continue;
            }
            res+=Math.min(n-i,limit)-Math.max(0,n-i-limit)+1;
        }
        return res;
    }
}